<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/9/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/9/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E7%AD%89%E5%B9%85%E5%80%BC%E5%8F%98%E6%8D%A2%E5%92%8C%E5%85%8B%E6%8B%89%E5%85%8B%E9%80%86%E5%8F%98%E6%8D%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E7%AD%89%E5%B9%85%E5%80%BC%E5%8F%98%E6%8D%A2%E5%92%8C%E5%85%8B%E6%8B%89%E5%85%8B%E9%80%86%E5%8F%98%E6%8D%A2/" class="post-title-link" itemprop="url">灯哥教程之等幅值变换和克拉克逆变换</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-27 16:14:35" itemprop="dateCreated datePublished" datetime="2023-05-27T16:14:35+08:00">2023-05-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E7%AD%89%E5%B9%85%E5%80%BC%E5%8F%98%E6%8D%A2%E5%92%8C%E5%85%8B%E6%8B%89%E5%85%8B%E9%80%86%E5%8F%98%E6%8D%A2/" class="post-meta-item leancloud_visitors" data-flag-title="灯哥教程之等幅值变换和克拉克逆变换" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E7%AD%89%E5%B9%85%E5%80%BC%E5%8F%98%E6%8D%A2%E5%92%8C%E5%85%8B%E6%8B%89%E5%85%8B%E9%80%86%E5%8F%98%E6%8D%A2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E7%AD%89%E5%B9%85%E5%80%BC%E5%8F%98%E6%8D%A2%E5%92%8C%E5%85%8B%E6%8B%89%E5%85%8B%E9%80%86%E5%8F%98%E6%8D%A2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文链接：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV13s4y1Z7Tg/?spm_id_from=333.788&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV13s4y1Z7Tg/?spm_id_from=333.788&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a></p>
<h3 id="等幅值变换"><a href="#等幅值变换" class="headerlink" title="等幅值变换"></a>等幅值变换</h3><p>​        我们先复习一下上一节中讲的知识：所谓克拉克变换，实际上就是降维解耦的过程，把难以辨明和控制的三相相位差120°电机波形降维为两维矢量。</p>
<p>​        上一节的最后引出了等幅值的克拉克变换：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271538818.png" style="zoom:80%;">

<p>​        何为等幅值变换？用α相电流输入1A电流的特例来举例，当电流输入时候，根据基尔霍夫电流定律（电路中任一个节点上，在任意时刻，<strong>流入节点</strong>的电流之和等于<strong>流出节点</strong>的电流之和，如下图），有：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271543223.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271543435.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271545463.png" style="zoom:77%;">

<p>​        <img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271549699.png" style="zoom:80%;"></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271551047.png" style="zoom:80%;">

<p>​        这就是<strong>克拉克变换的等幅值表现形式，总结一下它就是想建立出一种i_alpha=ia这么的一种简化的一个运算的环境</strong>。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271600404.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271602096.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271603089.png" style="zoom:80%;">

<h3 id="克拉克逆变换"><a href="#克拉克逆变换" class="headerlink" title="克拉克逆变换"></a>克拉克逆变换</h3><p>​        在上面，我们学习了怎么把一个三相时域上的复杂问题用矢量表示，并且用克拉克变换对它进行了降维，得到了降维后的简化表达形式。那么，有没有什么办法能够反过来把降维后的形式重新升维变回原来的ia,ib,ic三相电流波形呢？有，这就被称为克拉克逆变换。这个在后续的FOC算法中也会很常用到。趁热打铁，我们来看一看怎么进行克拉克逆变换。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271611440.png" style="zoom:80%;">

<p>​        在这里，我们终于就掌握了把三相电流波形进行降维（克拉克变换）的方法以及把降维后的结果还原回去的方法（克拉克逆变换）。通过克拉克变换对三相电流波形的降维，我们就可以以简单的二维坐标形式描述三相电机运转时的电流情况，这就为我们下一步深入建立电机的运动模型并且实现FOC奠定了基础。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%85%8B%E6%8B%89%E5%85%8B%E5%8F%98%E6%8D%A2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%85%8B%E6%8B%89%E5%85%8B%E5%8F%98%E6%8D%A2/" class="post-title-link" itemprop="url">灯哥教程之克拉克变换</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-27 15:32:21" itemprop="dateCreated datePublished" datetime="2023-05-27T15:32:21+08:00">2023-05-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%85%8B%E6%8B%89%E5%85%8B%E5%8F%98%E6%8D%A2/" class="post-meta-item leancloud_visitors" data-flag-title="灯哥教程之克拉克变换" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%85%8B%E6%8B%89%E5%85%8B%E5%8F%98%E6%8D%A2/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/27/%E7%81%AF%E5%93%A5%E6%95%99%E7%A8%8B%E4%B9%8B%E5%85%8B%E6%8B%89%E5%85%8B%E5%8F%98%E6%8D%A2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文链接：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1x84y1V76u/?spm_id_from=888.80997.embed_other.whitelist&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV1x84y1V76u/?spm_id_from=888.80997.embed_other.whitelist&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a> </p>
<p>​        我们先看下FOC算法流程图，我们现在在初学阶段还不需要知道它在说什么，我们只需要知道今天学习的是FOC的哪一部分算法即可。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271449621.png" style="zoom:70%;">

<p>​        FOC的过程其实就是输入需求的电机力矩，就把需求的电机力矩转化为三相线电力输出，并且让电机物理输出你所需要的力矩的过程。这也被称为电机控制三环中的力矩换，所有后面的位置闭环和速度闭环都得基于这个力矩环。而这个力矩环实际上就是一个无刷电机旋转状态的数学模型。</p>
<p>​        我们知道，交替开关的MOS管可以实现电机的转动，而这些交替开关的MOS管是以极其快的速度在周期性进行的，把这些周期性的开启和关断过程联系起来，并且对其各个相进行单独观察，就可以得到三个相A、B、C的电流随时间变换的曲线，如下图所示，他们之间存在120°的相位差。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271457876.png" style="zoom:67%;">

<p>​        换一个角度来思考此问题，实际上，我们只要能够控制这个相位差为120°的sin状波形，就能够实现针对电机的控制。</p>
<p>​        我们知道，虽然说是要控制120度的sin状型波形来实现电机控制，但是只要仔细想一想，就会知道这个波形其实是极难控制和改变参数的。首先相与相之间是相互耦合的，MOS管一打开就会至少同时打开两个相，所以只想改变一相来实现电机控制是肯定不行的，必须得三相捷联起来一起改变，才能够实现电机的控制。所以，实现电机控制的问题就会变成很复杂。</p>
<p>​        因此，我们需要对这个问题进行降维，尽量把这个多变量耦合的问题降解为最好是单一变量的控制问题，克拉克变换就是想做这件事。</p>
<p>​        所谓<strong>克拉克变换，实际上就是降维解耦的过程，把难以辨明和控制的三相相位差120°电机波形降维为两维矢量</strong>。</p>
<p>​        它的思路其实特别的简单，<strong>第一就是把三相随时间变换的，相位差为120°的电流波形抽象化为三个间隔120°的矢量。</strong></p>
<p>  <strong>第二就是利用三角函数对矢量进行降维，降维到两个坐标轴</strong>，从此复杂的三相变化问题就降解为了α-β坐标轴的坐标上的数值变化问题。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271508392.png" style="zoom:67%;">

<p>​        下面我们来进行一次投影过程的详细推导。</p>
<p>​        万恶之源的开始，就是三角函数：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271512231.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271513043.png" style="zoom:80%;">

<p>​        把上面的投影结果列成矩阵形式，有：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271514177.png" style="zoom:80%;">

<p>​        这就是<strong>克拉克变换的第一步，作投影。</strong></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271517493.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305271530336.png" style="zoom:80%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/27/arduino%E5%B9%B3%E5%8F%B0%E4%BD%BF%E7%94%A8AS5600/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/27/arduino%E5%B9%B3%E5%8F%B0%E4%BD%BF%E7%94%A8AS5600/" class="post-title-link" itemprop="url">arduino平台使用AS5600</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-27 09:19:21" itemprop="dateCreated datePublished" datetime="2023-05-27T09:19:21+08:00">2023-05-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/05/27/arduino%E5%B9%B3%E5%8F%B0%E4%BD%BF%E7%94%A8AS5600/" class="post-meta-item leancloud_visitors" data-flag-title="arduino平台使用AS5600" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/27/arduino%E5%B9%B3%E5%8F%B0%E4%BD%BF%E7%94%A8AS5600/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/27/arduino%E5%B9%B3%E5%8F%B0%E4%BD%BF%E7%94%A8AS5600/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        AS5600为绝对编码器，即根据安装的磁铁角度不同，初始位置的读数不同，读出来的数是当前初始位置在0~360°的一个值。使用的时候一定要使用径向磁铁，如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251014388.png" style="zoom:47%;">

<p>​        AS5600的iic地址为0X36，数据所在寄存器地址如下，0—4096对应0°—360°：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251020833.png"></p>
<p>​        使用灯哥的foc开发板，同时基于simplefoc库，测试一下AS5600，代码如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;SimpleFOC.h&gt;</span></span></span><br><span class="line"></span><br><span class="line">MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);</span><br><span class="line">TwoWire I2Ctwo = TwoWire(<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setup</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  Serial.begin(<span class="number">115200</span>);</span><br><span class="line">  _delay(<span class="number">750</span>);</span><br><span class="line">  I2Ctwo.begin(<span class="number">23</span>,<span class="number">5</span>, <span class="number">400000UL</span>);  <span class="comment">//给iic通道引脚和速率（sda，scl，speed）</span></span><br><span class="line">  sensor1.init(&amp;I2Ctwo);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">loop</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  sensor1.update();</span><br><span class="line">  Serial.print(sensor1.getAngle());</span><br><span class="line">  Serial.println();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​        串口源源不断的上传当前角度的弧度值，用手转动电机，角度随之变化，<strong>正转一圈角度增加6.28，反转一圈角度减小6.28</strong>。(simplefoc采用弧度制并且用角度累加方式显示角度，与我们平时的习惯稍微有点不符)</p>
<p>​        将代码小改一下，观察串口输出：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">loop</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  sensor1.update();</span><br><span class="line">  Serial.print(sensor1.getFullRotations()); </span><br><span class="line">  Serial.print(<span class="string">&quot; - &quot;</span>); </span><br><span class="line">  Serial.print(sensor1.getAngle());</span><br><span class="line">  Serial.println();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305270912359.png" style="zoom:80%;">

<p>​        增加了full_rotations这个变量的打印。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305270915198.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305270915418.png" style="zoom:80%;">

<p>​        上面的串口打印说明从0到4096不会发生overflow, 从4096到0就能检测到发生了overfolw。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/25/%E6%8A%BD%E8%B1%A1%E5%9F%BA%E7%B1%BB%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/25/%E6%8A%BD%E8%B1%A1%E5%9F%BA%E7%B1%BB%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0/" class="post-title-link" itemprop="url">抽象基类和纯虚函数</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-25 17:44:21" itemprop="dateCreated datePublished" datetime="2023-05-25T17:44:21+08:00">2023-05-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/" itemprop="url" rel="index"><span itemprop="name">编程语言</span></a>
                </span>
            </span>

          
            <span id="/2023/05/25/%E6%8A%BD%E8%B1%A1%E5%9F%BA%E7%B1%BB%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0/" class="post-meta-item leancloud_visitors" data-flag-title="抽象基类和纯虚函数" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/25/%E6%8A%BD%E8%B1%A1%E5%9F%BA%E7%B1%BB%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/25/%E6%8A%BD%E8%B1%A1%E5%9F%BA%E7%B1%BB%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        要创建抽象基类，可声明纯虚函数。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251744920.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251745625.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251746502.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251746471.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251747218.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251747889.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251752418.jpg"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/25/%E8%99%9A%E5%87%BD%E6%95%B0%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0%E7%9A%84%E5%8C%BA%E5%88%AB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/25/%E8%99%9A%E5%87%BD%E6%95%B0%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-title-link" itemprop="url">虚函数和纯虚函数的区别</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-25 17:39:51" itemprop="dateCreated datePublished" datetime="2023-05-25T17:39:51+08:00">2023-05-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/" itemprop="url" rel="index"><span itemprop="name">编程语言</span></a>
                </span>
            </span>

          
            <span id="/2023/05/25/%E8%99%9A%E5%87%BD%E6%95%B0%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-meta-item leancloud_visitors" data-flag-title="虚函数和纯虚函数的区别" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/25/%E8%99%9A%E5%87%BD%E6%95%B0%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0%E7%9A%84%E5%8C%BA%E5%88%AB/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/25/%E8%99%9A%E5%87%BD%E6%95%B0%E5%92%8C%E7%BA%AF%E8%99%9A%E5%87%BD%E6%95%B0%E7%9A%84%E5%8C%BA%E5%88%AB/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        虚函数为了重载和多态的需要，在基类中是有定义的，即便定义是空，所以子类中可以重写也可以不写基类中的此函数！</p>
<p>​       <strong>纯虚函数在基类中是没有定义的，必须在子类中加以实现，很像java中的接口函数！</strong></p>
<p><strong>虚函数和纯虚函数区别</strong></p>
<p>观点一：</p>
<p>​       类里声明为虚函数的话,这个函数是实现的，哪怕是空实现，它的作用就是为了能让这个函数在它的子类里面可以被重载，这样的话，这样编译器就可以使用后期绑定来达到多态了</p>
<p>​       纯虚函数只是一个接口，是个函数的声明而已，它要留到子类里去实现。</p>
<p>观点二：</p>
<p>​       虚函数在子类里面也可以不重载的；但纯虚必须在子类去实现，这就像Java的接口一样。通常我们把很多函数加上virtual，是一个好的习惯，虽然牺牲了一些性能，但是增加了面向对象的多态性，因为你很难预料到父类里面的这个函数不在子类里面不去修改它的实现。</p>
<p>观点三：</p>
<p>​       虚函数的类用于“实作继承”，继承接口的同时也继承了父类的实现。当然我们也可以完成自己的实现。纯虚函数的类用于“介面继承”，主要用于通信协议方面。关注的是接口的统一性，实现由子类完成。一般来说，介面类中只有纯虚函数的。</p>
<p>观点四：</p>
<p>​       <strong>带纯虚函数的类叫虚基类，这种基类不能直接生成对象，而只有被继承，并重写其虚函数后，才能使用。这样的类也叫抽象类</strong>。</p>
<p>​       虚函数是为了继承接口和默认行为</p>
<p>​       纯虚函数只是继承接口，行为必须重新定义 </p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/25/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA%E5%8F%8A%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/25/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA%E5%8F%8A%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA/" class="post-title-link" itemprop="url">为什么需要多态行为及如何实现多态行为</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-25 16:07:59" itemprop="dateCreated datePublished" datetime="2023-05-25T16:07:59+08:00">2023-05-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/" itemprop="url" rel="index"><span itemprop="name">编程语言</span></a>
                </span>
            </span>

          
            <span id="/2023/05/25/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA%E5%8F%8A%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA/" class="post-meta-item leancloud_visitors" data-flag-title="为什么需要多态行为及如何实现多态行为" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/25/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA%E5%8F%8A%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/25/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA%E5%8F%8A%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%A4%9A%E6%80%81%E8%A1%8C%E4%B8%BA/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h3 id="1-Why"><a href="#1-Why" class="headerlink" title="1.Why"></a>1.Why</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251608573.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251609118.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251610756.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251610227.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251611470.jpg"></p>
<h3 id="2-How-使用虚函数实现多态行为"><a href="#2-How-使用虚函数实现多态行为" class="headerlink" title="2.How(使用虚函数实现多态行为)"></a>2.How(使用虚函数实现多态行为)</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251617915.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251617128.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251618590.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251618982.jpg"></p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305251619875.jpg"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/23/%E4%BD%BF%E7%94%A8Arduino%E5%BC%80%E5%8F%91ESP32%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/23/%E4%BD%BF%E7%94%A8Arduino%E5%BC%80%E5%8F%91ESP32%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" class="post-title-link" itemprop="url">使用Arduino开发ESP32开发环境搭建</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-23 10:06:15" itemprop="dateCreated datePublished" datetime="2023-05-23T10:06:15+08:00">2023-05-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2023/05/23/%E4%BD%BF%E7%94%A8Arduino%E5%BC%80%E5%8F%91ESP32%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" class="post-meta-item leancloud_visitors" data-flag-title="使用Arduino开发ESP32开发环境搭建" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/23/%E4%BD%BF%E7%94%A8Arduino%E5%BC%80%E5%8F%91ESP32%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/23/%E4%BD%BF%E7%94%A8Arduino%E5%BC%80%E5%8F%91ESP32%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文：<a target="_blank" rel="noopener" href="https://blog.csdn.net/book_drabit/article/details/125089418">https://blog.csdn.net/book_drabit/article/details/125089418</a></p>
<h3 id="下载开发环境"><a href="#下载开发环境" class="headerlink" title="下载开发环境"></a>下载开发环境</h3><p>​        官网连接路径：<a target="_blank" rel="noopener" href="https://www.arduino.cc/en/software%EF%BC%8C">https://www.arduino.cc/en/software，</a> 下载ZIP文件即可。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221700136.png" style="zoom:57%;">

<p>完成下载后，直接解压即可运行。</p>
<h3 id="安装开发环境"><a href="#安装开发环境" class="headerlink" title="安装开发环境"></a>安装开发环境</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221703526.png" style="zoom:67%;">

<p>​        发现这里没有ESP32开发板，下面进行ESP32开发环境安装。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221705419.png" style="zoom:80%;">

<p>​        进入首选项。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221706606.png" style="zoom:67%;">

<p>​        这里输入ESP32 ARDUINO的网址，<strong>安装2.0.9版本的ESP32环境</strong>，需要将上述网址设为：</p>
<p>​        <a target="_blank" rel="noopener" href="https://espressif.github.io/arduino-esp32/package_esp32_index.json">https://espressif.github.io/arduino-esp32/package_esp32_index.json</a></p>
<p>​        然后再次进入工具-&gt;开发板-&gt;开发板管理器</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221711932.png" style="zoom:80%;">

<p>​        这个下载会非常慢，安装需要一定时间。下载完成后记得配置一下自己用的开发板。</p>
<h3 id="测试demo"><a href="#测试demo" class="headerlink" title="测试demo"></a>测试demo</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305231001113.png" style="zoom:60%;">

<p>​        代码编写好后，点击上传按钮。在下载的时候，需要我们按下esp32板子上的boot按键就下载成功了。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305231006652.png" style="zoom:60%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/23/%E6%97%A0%E5%88%B7%E7%94%B5%E6%9C%BA%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/23/%E6%97%A0%E5%88%B7%E7%94%B5%E6%9C%BA%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/" class="post-title-link" itemprop="url">无刷电机工作原理</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-23 07:58:14" itemprop="dateCreated datePublished" datetime="2023-05-23T07:58:14+08:00">2023-05-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%94%B5%E6%9C%BA/" itemprop="url" rel="index"><span itemprop="name">电机</span></a>
                </span>
            </span>

          
            <span id="/2023/05/23/%E6%97%A0%E5%88%B7%E7%94%B5%E6%9C%BA%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/" class="post-meta-item leancloud_visitors" data-flag-title="无刷电机工作原理" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/23/%E6%97%A0%E5%88%B7%E7%94%B5%E6%9C%BA%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/23/%E6%97%A0%E5%88%B7%E7%94%B5%E6%9C%BA%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Fe4y117pS/?spm_id_from=333.788.top_right_bar_window_default_collection.content.click&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV1Fe4y117pS/?spm_id_from=333.788.top_right_bar_window_default_collection.content.click&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a></p>
<h3 id="1-组成"><a href="#1-组成" class="headerlink" title="1.组成"></a>1.组成</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230758150.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230759714.png" style="zoom:50%;">

<p>​        通常永磁体是转子，因为是电路控制电流方向，用永磁体作为转子能够提高效率。</p>
<h3 id="2-工作原理"><a href="#2-工作原理" class="headerlink" title="2.工作原理"></a>2.工作原理</h3><p>​        给线圈通电，就会产生磁场，对转子的永磁体产生吸引力。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230803557.png" style="zoom:50%;">

<p>​        如果挨个激活线圈，转子就会持续不断受到吸引力而一直转下去。</p>
<p>​        为了提高效率，我们可以<strong>相反方向缠绕并连接相对的</strong>两个线圈，这样可以实现控制一条线的电流，产生两倍的吸引力或者是排斥力。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230808400.png" style="zoom:57%;">

<p>​        依次按照这样的方式连接线圈，发现好像还能继续优化，即同时给两对线圈通电，并给相反方向电流。这样上一个线圈给排斥力的同时，下一个线圈施加吸引力，电机的效率进一步提高。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230812304.png" style="zoom:57%;">

<p>​        但是这样需要开关线圈中的电流6次，才能实现转子旋转360度。要简化这个问题，我们先来看看电流正负变化的情况，如下图所示，在每个单位间隔内，都是一组线圈为正向电流，一组为反向电流，另一组无电流：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230827004.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230828367.gif" style="zoom:67%;">

<p>​        根据这个规律，可以用一种连接方法实现电流的共享。举例说明，比如在A相线圈处连接电源正极，在B相线圈处接地。电流从正级流过A相线圈后，经过黑色导线流入B相线圈，最终在B点接地，这样变成两组线圈串联，实现了单一电流控制4个线圈。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230839982.gif" style="zoom:57%;">

<p>​        这种连接叫做星形接法，中性的黑色导线是三组线圈的交点。为了完成每组线圈的精确控制，我们只需要在正确的时间激活两个开关，形成一条完整闭合回路即可。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230840911.gif" style="zoom:67%;">

<h3 id="3-无刷电机控制器图示"><a href="#3-无刷电机控制器图示" class="headerlink" title="3.无刷电机控制器图示"></a>3.无刷电机控制器图示</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230845831.png" style="zoom:67%;">

<p>​        通过激活合适的两个开关，实现了同时对两组线圈的电流控制，开关开启和关闭的频率越高，或者电流流过线圈的速度越快，电机的转速就会越高。</p>
<p>​        看到这里有个疑问，我们如何知道什么时候该开或者关哪两个开关呢？答案是知道转子的位置即可。而确定转子位置的方法常用的有两种，一种如图所示，线圈之间嵌入霍尔传感器，每个霍尔传感器间隔120度，<strong>霍尔传感器能够感应转子磁场的转变，并转成电信号输出</strong>。控制器中的芯片根据这些信息，就能够计算和控制电路开关了。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230904544.png" style="zoom:57%;">

<p>​        </p>
<p>​        第二种方法就是测反电动势，反电动势的原理其实就是电磁感应定律，闭合回路的导线的一部分做切割磁感线的运动时，导线内就会产生感应电流，所以当永磁体的转子转动时，它周围的磁场会通过未通电的线圈，从而导致该线圈内产生感应电流。这样的变化被电流传感器捕获，并同样转换成电信号输出，控制器根据这些信号计算转子的位置。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230912534.png" style="zoom:57%;">

<h3 id="4-引申"><a href="#4-引申" class="headerlink" title="4.引申"></a>4.引申</h3><p>​        当然一般无刷电机不止6级，但基本仍是三相，只是同时控制的线圈数量会增加。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230918905.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305230919856.png" style="zoom:67%;">

<p>​        内转子的转速更快，外转子的力矩更大。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/22/STM32%E4%B8%AD%E6%96%AD%E5%90%91%E9%87%8F%E8%A1%A8%E5%8E%9F%E7%90%86%E5%92%8C%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/22/STM32%E4%B8%AD%E6%96%AD%E5%90%91%E9%87%8F%E8%A1%A8%E5%8E%9F%E7%90%86%E5%92%8C%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8/" class="post-title-link" itemprop="url">STM32中断向量表原理和实际使用</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-22 19:52:42" itemprop="dateCreated datePublished" datetime="2023-05-22T19:52:42+08:00">2023-05-22</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2023/05/22/STM32%E4%B8%AD%E6%96%AD%E5%90%91%E9%87%8F%E8%A1%A8%E5%8E%9F%E7%90%86%E5%92%8C%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8/" class="post-meta-item leancloud_visitors" data-flag-title="STM32中断向量表原理和实际使用" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/22/STM32%E4%B8%AD%E6%96%AD%E5%90%91%E9%87%8F%E8%A1%A8%E5%8E%9F%E7%90%86%E5%92%8C%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/22/STM32%E4%B8%AD%E6%96%AD%E5%90%91%E9%87%8F%E8%A1%A8%E5%8E%9F%E7%90%86%E5%92%8C%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Sg4y1G7be/?spm_id_from=333.1007.top_right_bar_window_default_collection.content.click&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8">https://www.bilibili.com/video/BV1Sg4y1G7be/?spm_id_from=333.1007.top_right_bar_window_default_collection.content.click&amp;vd_source=2ef3411e1c045a25cc2351abaa2c3ce8</a></p>
<h3 id="什么是中断向量表"><a href="#什么是中断向量表" class="headerlink" title="什么是中断向量表"></a>什么是中断向量表</h3><p>​        就是中断服务函数地址的表。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305222003159.png" style="zoom:67%;">

<p>​        中断向量表就定义在startup文件中：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305222004298.png" style="zoom:70%;">

<p>​        第一项是栈顶指针；第二项是复位中断服务函数，这是arm上电后真正的入口函数；接下来是不可屏蔽中断服务函数；总共有100多项。</p>
<p>​        中断向量表就放置在文件最开始的位置，如下所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305222010212.png" style="zoom:80%;">

<h3 id="中断向量表重映射"><a href="#中断向量表重映射" class="headerlink" title="中断向量表重映射"></a>中断向量表重映射</h3><p>​        这个是中断向量表很重要的一个功能，这会用在有bootloader的项目中。</p>
<p>​        <strong>bootloader跳转到app后</strong>，<strong>如果不做中断向量表重映射，当app发生中断后，就会跳转到bootloader的中断服务函数中，这样显然是不对的</strong>。</p>
<p>​        重映射也很简单，只要设定中断向量表偏移寄存器SCB-&gt;VTOR。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305222015292.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/05/22/FPGA%E5%92%8Cstm32%E9%80%9A%E8%BF%87FSMC%E9%80%9A%E4%BF%A1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/05/22/FPGA%E5%92%8Cstm32%E9%80%9A%E8%BF%87FSMC%E9%80%9A%E4%BF%A1/" class="post-title-link" itemprop="url">FPGA和stm32通过FSMC通信</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-05-22 10:25:29" itemprop="dateCreated datePublished" datetime="2023-05-22T10:25:29+08:00">2023-05-22</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/FPGA/" itemprop="url" rel="index"><span itemprop="name">FPGA</span></a>
                </span>
            </span>

          
            <span id="/2023/05/22/FPGA%E5%92%8Cstm32%E9%80%9A%E8%BF%87FSMC%E9%80%9A%E4%BF%A1/" class="post-meta-item leancloud_visitors" data-flag-title="FPGA和stm32通过FSMC通信" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/05/22/FPGA%E5%92%8Cstm32%E9%80%9A%E8%BF%87FSMC%E9%80%9A%E4%BF%A1/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/05/22/FPGA%E5%92%8Cstm32%E9%80%9A%E8%BF%87FSMC%E9%80%9A%E4%BF%A1/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考的文章地址：<a target="_blank" rel="noopener" href="https://www.armbbs.cn/forum.php?mod=viewthread&amp;tid=596&amp;extra=page=1">https://www.armbbs.cn/forum.php?mod=viewthread&amp;tid=596&amp;extra=page%3D1</a></p>
<p>​        <img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221025561.jpg" style="zoom:80%;"></p>
<p>FSMC采用模式A，读写时序如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221026415.jpg" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221026798.jpg" style="zoom:80%;">

<h3 id="FPGA端"><a href="#FPGA端" class="headerlink" title="FPGA端"></a>FPGA端</h3><figure class="highlight verilog"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">module</span> fsmc(</span><br><span class="line">    <span class="keyword">input</span>[<span class="number">2</span>:<span class="number">0</span>] AB,    <span class="comment">//地址</span></span><br><span class="line">    <span class="keyword">inout</span>[<span class="number">15</span>:<span class="number">0</span>]  DB,  <span class="comment">//数据</span></span><br><span class="line">    <span class="keyword">input</span> Selectn,    <span class="comment">//FPGA片选</span></span><br><span class="line">    <span class="keyword">input</span> WRn,</span><br><span class="line">    <span class="keyword">input</span> RDn</span><br><span class="line">    );</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outa;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outb;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outc;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outd;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] oute;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outf;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outg;</span><br><span class="line">    <span class="keyword">reg</span>[<span class="number">15</span>:<span class="number">0</span>] outh;</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    <span class="keyword">reg</span> [<span class="number">15</span>:<span class="number">0</span>] indata;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">    !RDn用于控制DB的方向</span></span><br><span class="line"><span class="comment">    RDn为0时，DB就是作为输出口，对indata赋值就可以了</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">    <span class="keyword">assign</span> DB = !RDn ? indata:<span class="number">16&#x27;hzzzz</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//mcu写数据,根据地址线选择八个空间中的一个写入</span></span><br><span class="line">    <span class="keyword">always</span> @(<span class="keyword">negedge</span> WRn)</span><br><span class="line">        <span class="keyword">begin</span></span><br><span class="line">           <span class="keyword">if</span>(Selectn == <span class="number">0</span>)</span><br><span class="line">            <span class="keyword">begin</span></span><br><span class="line">                <span class="keyword">case</span>(AB)</span><br><span class="line">                    <span class="number">3&#x27;b000</span>:outa &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b001</span>:outb &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b010</span>:outc &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b011</span>:outd &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b100</span>:oute &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b101</span>:outf &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b110</span>:outg &lt;= DB;</span><br><span class="line">                    <span class="number">3&#x27;b111</span>:outh &lt;= DB;</span><br><span class="line">                    <span class="keyword">default</span>:;</span><br><span class="line">                <span class="keyword">endcase</span></span><br><span class="line">            <span class="keyword">end</span> </span><br><span class="line">        <span class="keyword">end</span></span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">    <span class="comment">//mcu读数据，根据地址线选择八个空间中一个来读取</span></span><br><span class="line">    <span class="keyword">always</span> @(RDn)</span><br><span class="line">        <span class="keyword">begin</span></span><br><span class="line">            <span class="keyword">if</span>(Selectn == <span class="number">0</span>)</span><br><span class="line">                <span class="keyword">begin</span></span><br><span class="line">                    <span class="keyword">case</span>(AB)</span><br><span class="line">                        <span class="number">3&#x27;b000</span>:indata &lt;= outa;</span><br><span class="line">                        <span class="number">3&#x27;b001</span>:indata &lt;= outb;</span><br><span class="line">                        <span class="number">3&#x27;b010</span>:indata &lt;= outc;</span><br><span class="line">                        <span class="number">3&#x27;b011</span>:indata &lt;= outd;</span><br><span class="line">                        <span class="number">3&#x27;b100</span>:indata &lt;= oute;</span><br><span class="line">                        <span class="number">3&#x27;b101</span>:indata &lt;= outf;</span><br><span class="line">                        <span class="number">3&#x27;b110</span>:indata &lt;= outg;</span><br><span class="line">                        <span class="number">3&#x27;b111</span>:indata &lt;= outh;</span><br><span class="line">                        <span class="keyword">default</span>:;</span><br><span class="line">                    <span class="keyword">endcase</span></span><br><span class="line">            <span class="keyword">end</span></span><br><span class="line">        <span class="keyword">end</span></span><br><span class="line">        </span><br><span class="line"><span class="keyword">endmodule</span></span><br></pre></td></tr></table></figure>
<h3 id="MCU端"><a href="#MCU端" class="headerlink" title="MCU端"></a>MCU端</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221041117.png" style="zoom:70%;">

<p>stm32_sram.c</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32_sram.h&quot;</span></span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">uint32_t</span> FSMC_Initialized = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">HAL_FSMC_MspInit</span><span class="params">(<span class="keyword">void</span>)</span></span>&#123;</span><br><span class="line">  <span class="comment">/* USER CODE BEGIN FSMC_MspInit 0 */</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">/* USER CODE END FSMC_MspInit 0 */</span></span><br><span class="line">  GPIO_InitTypeDef GPIO_InitStruct =&#123;<span class="number">0</span>&#125;;</span><br><span class="line">  <span class="keyword">if</span> (FSMC_Initialized) &#123;</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  FSMC_Initialized = <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/* Peripheral clock enable */</span></span><br><span class="line">  __HAL_RCC_FSMC_CLK_ENABLE();</span><br><span class="line"></span><br><span class="line">	<span class="comment">/* GPIO Ports Clock Enable */</span></span><br><span class="line">	__HAL_RCC_GPIOF_CLK_ENABLE();</span><br><span class="line">	__HAL_RCC_GPIOE_CLK_ENABLE();</span><br><span class="line">	__HAL_RCC_GPIOD_CLK_ENABLE();</span><br><span class="line">	</span><br><span class="line">  <span class="comment">/** FSMC GPIO Configuration</span></span><br><span class="line"><span class="comment">  PF0   ------&gt; FSMC_A0</span></span><br><span class="line"><span class="comment">  PF1   ------&gt; FSMC_A1</span></span><br><span class="line"><span class="comment">  PF2   ------&gt; FSMC_A2</span></span><br><span class="line"><span class="comment">  PE7   ------&gt; FSMC_D4</span></span><br><span class="line"><span class="comment">  PE8   ------&gt; FSMC_D5</span></span><br><span class="line"><span class="comment">  PE9   ------&gt; FSMC_D6</span></span><br><span class="line"><span class="comment">  PE10   ------&gt; FSMC_D7</span></span><br><span class="line"><span class="comment">  PE11   ------&gt; FSMC_D8</span></span><br><span class="line"><span class="comment">  PE12   ------&gt; FSMC_D9</span></span><br><span class="line"><span class="comment">  PE13   ------&gt; FSMC_D10</span></span><br><span class="line"><span class="comment">  PE14   ------&gt; FSMC_D11</span></span><br><span class="line"><span class="comment">  PE15   ------&gt; FSMC_D12</span></span><br><span class="line"><span class="comment">  PD8   ------&gt; FSMC_D13</span></span><br><span class="line"><span class="comment">  PD9   ------&gt; FSMC_D14</span></span><br><span class="line"><span class="comment">  PD10   ------&gt; FSMC_D15</span></span><br><span class="line"><span class="comment">  PD14   ------&gt; FSMC_D0</span></span><br><span class="line"><span class="comment">  PD15   ------&gt; FSMC_D1</span></span><br><span class="line"><span class="comment">  PD0   ------&gt; FSMC_D2</span></span><br><span class="line"><span class="comment">  PD1   ------&gt; FSMC_D3</span></span><br><span class="line"><span class="comment">  PD4   ------&gt; FSMC_NOE</span></span><br><span class="line"><span class="comment">  PD5   ------&gt; FSMC_NWE</span></span><br><span class="line"><span class="comment">  PD7   ------&gt; FSMC_NE1</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;</span><br><span class="line">  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;</span><br><span class="line">  GPIO_InitStruct.Pull = GPIO_NOPULL;</span><br><span class="line">  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;</span><br><span class="line">  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;</span><br><span class="line">  HAL_GPIO_Init(GPIOF, &amp;GPIO_InitStruct);</span><br><span class="line"></span><br><span class="line">  GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10</span><br><span class="line">                          |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14</span><br><span class="line">                          |GPIO_PIN_15;</span><br><span class="line">  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;</span><br><span class="line">  GPIO_InitStruct.Pull = GPIO_NOPULL;</span><br><span class="line">  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;</span><br><span class="line">  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;</span><br><span class="line">  HAL_GPIO_Init(GPIOE, &amp;GPIO_InitStruct);</span><br><span class="line"></span><br><span class="line">  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14</span><br><span class="line">                          |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4</span><br><span class="line">                          |GPIO_PIN_5|GPIO_PIN_7;</span><br><span class="line">  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;</span><br><span class="line">  GPIO_InitStruct.Pull = GPIO_NOPULL;</span><br><span class="line">  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;</span><br><span class="line">  GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;</span><br><span class="line">  HAL_GPIO_Init(GPIOD, &amp;GPIO_InitStruct);</span><br><span class="line"></span><br><span class="line">  <span class="comment">/* USER CODE BEGIN FSMC_MspInit 1 */</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">/* USER CODE END FSMC_MspInit 1 */</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">HAL_SRAM_MspInit</span><span class="params">(SRAM_HandleTypeDef* hsram)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">		HAL_FSMC_MspInit();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">SRAM_HandleTypeDef hsram1;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">FSMC_Init</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">		FSMC_NORSRAM_TimingTypeDef Timing = &#123;<span class="number">0</span>&#125;;</span><br><span class="line">		hsram1.Instance = FSMC_NORSRAM_DEVICE;</span><br><span class="line">		hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;</span><br><span class="line">		<span class="comment">/* hsram1.Init */</span></span><br><span class="line">		hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;</span><br><span class="line">		hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;</span><br><span class="line">		hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;</span><br><span class="line">		hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;</span><br><span class="line">		hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;</span><br><span class="line">		hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;</span><br><span class="line">		hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;</span><br><span class="line">		hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;</span><br><span class="line">		hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;</span><br><span class="line">		hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;</span><br><span class="line">		hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;</span><br><span class="line">		hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;</span><br><span class="line">		hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;</span><br><span class="line">		hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE;</span><br><span class="line">		<span class="comment">/* Timing */</span></span><br><span class="line">		Timing.AddressSetupTime = <span class="number">0</span>;</span><br><span class="line">		Timing.AddressHoldTime = <span class="number">15</span>;</span><br><span class="line">		Timing.DataSetupTime = <span class="number">7</span>;</span><br><span class="line">		Timing.BusTurnAroundDuration = <span class="number">0</span>;</span><br><span class="line">		Timing.CLKDivision = <span class="number">16</span>;</span><br><span class="line">		Timing.DataLatency = <span class="number">17</span>;</span><br><span class="line">		Timing.AccessMode = FSMC_ACCESS_MODE_A;</span><br><span class="line">		<span class="comment">/* ExtTiming */</span></span><br><span class="line">		<span class="keyword">if</span> (HAL_SRAM_Init(&amp;hsram1, &amp;Timing, <span class="literal">NULL</span>) != HAL_OK)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">while</span>(<span class="number">1</span>);</span><br><span class="line">		&#125;		</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>stm32_sram.h</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> __STM32_SRAM_H__</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> __STM32_SRAM_H__</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32f4xx_hal.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">//定义如下STM32与FPGA间通信用的寄存器,   </span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG0	*((volatile unsigned short *)((u32)0x60000000))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG1	*((volatile unsigned short *)((u32)0x60000002))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG2	*((volatile unsigned short *)((u32)0x60000004))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG3	*((volatile unsigned short *)((u32)0x60000006))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG4	*((volatile unsigned short *)((u32)0x60000008))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG5	*((volatile unsigned short *)((u32)0x6000000A))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG6	*((volatile unsigned short *)((u32)0x6000000C))</span></span><br><span class="line"><span class="comment">//#define	ARM_FPGA_REG7	*((volatile unsigned short *)((u32)0x6000000E))</span></span><br><span class="line">	</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">FSMC_Init</span><span class="params">(<span class="keyword">void</span>)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fpga_write(offset,data)	*((volatile unsigned short *)(0x60000000 + (offset &lt;&lt; 1))) = data</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fpga_read(offset)	*((volatile unsigned short *)(0x60000000 + (offset &lt;&lt; 1)))</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br></pre></td></tr></table></figure>
<p>测试代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32f4xx_hal.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32_clock.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32_uart.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32_gpio.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;stm32_sram.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">short</span> test_buf[<span class="number">8</span>] = &#123;<span class="number">12</span>,<span class="number">45</span>,<span class="number">56</span>,<span class="number">78</span>,<span class="number">91</span>,<span class="number">13</span>,<span class="number">24</span>,<span class="number">57</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">unsigned</span> <span class="keyword">short</span> fsmc_read_data = <span class="number">0</span>;</span><br><span class="line">  	HAL_Init();</span><br><span class="line">  	SystemClock_Config();</span><br><span class="line">	LED_Init();</span><br><span class="line">	UART_Init();</span><br><span class="line">	FSMC_Init();</span><br><span class="line"> </span><br><span class="line">  	<span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line">  	&#123;</span><br><span class="line">		  <span class="built_in">printf</span>(<span class="string">&quot;=================\r\n&quot;</span>);</span><br><span class="line">		  <span class="comment">//LED0_Toggle();</span></span><br><span class="line">		  <span class="comment">//HAL_Delay(1000);</span></span><br><span class="line">		  <span class="keyword">for</span>(<span class="keyword">uint8_t</span> i=<span class="number">0</span>; i&lt;<span class="number">8</span>; i++)  <span class="comment">//向FPGA写入数据</span></span><br><span class="line">		  &#123;</span><br><span class="line">				fpga_write(i, test_buf[i]);</span><br><span class="line">		  &#125;</span><br><span class="line">		  <span class="keyword">for</span>(<span class="keyword">uint8_t</span> i=<span class="number">0</span>; i&lt;<span class="number">8</span>; i++)</span><br><span class="line">		  &#123;</span><br><span class="line">				fsmc_read_data = fpga_read(i);   <span class="comment">//从FPGA读数据</span></span><br><span class="line">				<span class="built_in">printf</span>(<span class="string">&quot;%d read:%d\r\n&quot;</span>, i, fsmc_read_data);</span><br><span class="line">				HAL_Delay(<span class="number">400</span>);</span><br><span class="line">		  &#125;</span><br><span class="line">		  HAL_Delay(<span class="number">1000</span>);</span><br><span class="line">  	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221116448.jpg" style="zoom:37%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202305221117322.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/8/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/8/">8</a><span class="page-number current">9</span><a class="page-number" href="/page/10/">10</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/10/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
